#include "measurepage_p2.h"
#include "ui_measurepage_p2.h"
#include "Beans/userinfobeab.h"
#include "QDateTime"
#include "DBOperation/mysql.h"
#include "Config/constant.h"
#include "HRVPro/hrvdataprocess.h"
#include "Report/mentalreport.h"
#include<QtPrintSupport/QPrinter>
#include "dialog/myhelper.h"
#include "Report/printreport.h"
#include "Report/login.h"
#include "Report/anf.h"
#include "Report/hrv.h"
#include "Report/appgreport.h"

MeasurePage_P2::MeasurePage_P2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MeasurePage_P2)
{
    ui->setupUi(this);
    InitialChartView();
    setBg();
    if(Constant::ShowFullScreen)
        this->showFullScreen();
    ui->tabWidget_p1->setCurrentIndex(0);
    ui->tabWidget_p2->setCurrentIndex(0);
    ui->progressBar_psi->setTextVisible(false);
    ui->progressBar_mental->setTextVisible(false);
    ui->progressBar_Fatigure->setTextVisible(false);
    ui->progressBar_RegistPressure->setTextVisible(false);

    ui->progressBar_psi_2->setTextVisible(false);
    ui->progressBar_mental_2->setTextVisible(false);
    ui->progressBar_Fatigure_2->setTextVisible(false);
    ui->progressBar_RegistPressure_2->setTextVisible(false);

    myplayer=new QMediaPlayer();
    audioOutput=new QAudioOutput();
    audioOutput->setVolume(100);
    myplayer->setAudioOutput(audioOutput);
    myplayer->setSource(QUrl("qrc:/sound/info.mp3"));
    QSettings *setting=new QSettings("./Configuration.ini",QSettings::IniFormat);
    setting->beginGroup("Config");
    printType=setting->value("PrintType").toString();
    setting->endGroup();
    delete setting;
}

MeasurePage_P2::~MeasurePage_P2()
{
    delete audioOutput;
    delete myplayer;
    delete ppg_Chart;
    delete appg_Chart;
    delete hrv_Chart;
    delete ppg_Chart2;
    delete appg_Chart2;
    delete hrv_Chart2;
    delete ui;
}
/**
 * 功能：设置背景图片
 * @brief WelcomePage::setBg
 */
void MeasurePage_P2::setBg()
{
    QPalette pal = this->palette();
    pal.setBrush(QPalette::Window,QBrush(QPixmap(":/images/MeasurePage/measure_bg.png")));
    setPalette(pal);
}
void MeasurePage_P2::InitialControl2()
{
    ui->tabWidget_p1->setCurrentIndex(0);
    ui->tabWidget_p2->setCurrentIndex(0);
    initControl(1);
    initControl(2);
}

void MeasurePage_P2::initControl(int p)
{
    if(p==1){
        ui->Mesure_label_ID_V->setText("");

        ui->label_hr_v->setText("--");
        ui->label_ox_v->setText("--");
        ui->progressBar->setValue(0);
        ui->lineEdit_ID->setText("");
        QDateTime Time = QDateTime::currentDateTime();
        ui->lineEdit_ID->setText(Time.toString("yyyyMMddhhmmss_1"));
        ui->lineEdit_Name->setText("");
        ui->lineEdit_Age->setText("");
        ui->lineEdit_height->setText("");
        ui->lineEdit_weight->setText("");
    }

    if(p==2){
        ui->Mesure_label_ID_V_2->setText("");

        ui->label_hr_v_2->setText("--");
        ui->label_ox_v_2->setText("--");
        ui->progressBar_2->setValue(0);
        ui->lineEdit_ID_2->setText("");
        QDateTime Time = QDateTime::currentDateTime();
        ui->lineEdit_ID_2->setText(Time.toString("yyyyMMddhhmmss_2"));
        ui->lineEdit_Name_2->setText("");
        ui->lineEdit_Age_2->setText("");
        ui->lineEdit_height_2->setText("");
        ui->lineEdit_weight_2->setText("");
    }

    pos1=0;
    pos2=0;
}
void MeasurePage_P2::on_bt_ok_p1_clicked()
{
    QString id=ui->lineEdit_ID->text();
    QString name=ui->lineEdit_Name->text();
    QString age=ui->lineEdit_Age->text();
    QString sex=ui->comboBox->currentText();
    QString height=ui->lineEdit_height->text();
    QString weight=ui->lineEdit_weight->text();
    uib1.UserID=id;
    uib1.UserName=name;
    uib1.UserAge=age;
    uib1.UserSex=sex;
    uib1.UserHeight=height;
    uib1.UserWeight=weight;
    qDebug()<<"UserSex"<<sex;
    QDateTime Time = QDateTime::currentDateTime();
    uib1.MeasureTime=Time.toString("yyyy-MM-dd hh:mm:ss");//格式化时间

    if(id.length()>0)
    {
        if(age.size()>0)
        {
            if(age.toInt()>0 && age.toInt()<100)
            {
                ui->tabWidget_p1->setCurrentIndex(1);
                myplayer->play();
                emit sendUserInfo2Thread2(uib1,1);
                ui->Mesure_label_ID_V->setText(uib1.UserID);
                ui->Mesure_label_Name_V->setText(uib1.UserName);
                emit sendStartOrStop2(true,1);
            }else
            {
                ui->lineEdit_Age->setPlaceholderText("年龄范围（0-99）");
            }
        }else
        {
            ui->lineEdit_Age->setPlaceholderText("年龄不能为空");
        }


    }else
    {
        ui->lineEdit_ID->setPlaceholderText("编号不能为空");

    }

}


void MeasurePage_P2::on_bt_ok_p2_clicked()
{
    QString id=ui->lineEdit_ID_2->text();
    QString name=ui->lineEdit_Name_2->text();
    QString age=ui->lineEdit_Age_2->text();
    QString sex=ui->comboBox_2->currentText();
    QString height=ui->lineEdit_height_2->text();
    QString weight=ui->lineEdit_weight_2->text();
    uib2.UserID=id;
    uib2.UserName=name;
    uib2.UserAge=age;
    uib2.UserSex=sex;
    uib2.UserHeight=height;
    uib2.UserWeight=weight;
    qDebug()<<"UserSex"<<sex;
    QDateTime Time = QDateTime::currentDateTime();
    uib2.MeasureTime=Time.toString("yyyy-MM-dd hh:mm:ss");//格式化时间

    if(id.length()>0)
    {
        if(age.size()>0)
        {
            if(age.toInt()>0 && age.toInt()<100)
            {
                ui->tabWidget_p2->setCurrentIndex(1);
                myplayer->play();
                emit sendUserInfo2Thread2(uib2,2);
                ui->Mesure_label_ID_V_2->setText(uib2.UserID);
                ui->Mesure_label_Name_V2->setText(uib2.UserName);
                emit sendStartOrStop2(true,2);
            }else
            {
                ui->lineEdit_Age_2->setPlaceholderText("年龄范围（0-99）");
            }
        }else
        {
            ui->lineEdit_Age_2->setPlaceholderText("年龄不能为空");
        }


    }else
    {
        ui->lineEdit_ID_2->setPlaceholderText("编号不能为空");

    }
}

/**
 * @brief MeasurePage_P1::InitialChartView
 * 功能：初始化波形图
 */
void MeasurePage_P2::InitialChartView()
{
    ppg_Chart=MPC.CreateLineChart_PPG1();
    ui->ChartView_PPG->setChart(ppg_Chart);
    ui->ChartView_PPG->setRenderHint(QPainter::Antialiasing, true);//设置无锯齿

    appg_Chart=MPC.CreateLineChart_APPG1();
    ui->ChartView_APPG->setChart(appg_Chart);
    ui->ChartView_APPG->setRenderHint(QPainter::Antialiasing, true);//设置无锯齿

    hrv_Chart=MPC.CreateHRVHistBarChart();
    ui->ChartView_HRV->setChart(hrv_Chart);
    ui->ChartView_HRV->setRenderHint(QPainter::Antialiasing, true);//设置无锯齿

    ppg_Chart2=MPC.CreateLineChart_PPG2();
    ui->ChartView_PPG_2->setChart(ppg_Chart2);
    ui->ChartView_PPG_2->setRenderHint(QPainter::Antialiasing, true);//设置无锯齿

    appg_Chart2=MPC.CreateLineChart_APPG2();
    ui->ChartView_APPG_2->setChart(appg_Chart2);
    ui->ChartView_APPG_2->setRenderHint(QPainter::Antialiasing, true);//设置无锯齿

    hrv_Chart2=MPC.CreateHRVHistBarChart2();
    ui->ChartView_HRV_2->setChart(hrv_Chart2);
    ui->ChartView_HRV_2->setRenderHint(QPainter::Antialiasing, true);//设置无锯齿
}
void MeasurePage_P2::getPPGData(double ppg1,double appg1,double ppg2,double appg2)
{
//    qDebug()<<"getPPGData1="<<ppg1;
//    qDebug()<<"getPPGData2="<<ppg2;
    MPC.Update_PPGData1(ppg1);
    MPC.Update_APPGData1(appg1);
    MPC.Update_PPGData2(ppg2);
    MPC.Update_APPGData2(appg2);
}
void MeasurePage_P2::getHRData(unsigned char hr,int p)
{

    if(p==1){
        if(hr==0)
            pos1=0;
        ui->label_hr_v->setText(QString::number(hr));
    }
    if(p==2){
        if(hr==0)
            pos2=0;
        ui->label_hr_v_2->setText(QString::number(hr));
    }
}
void MeasurePage_P2::getSPOXData(double spox,int p)
{
    if(p==1){
        if(spox==0)
            pos1=0;
        ui->label_ox_v->setText(QString::number(spox,'f',1));
    }
    if(p==2){
        if(spox==0)
            pos2=0;
        ui->label_ox_v_2->setText(QString::number(spox,'f',1));
    }
}
void MeasurePage_P2::getRRData(int RR,int p)
{
    if(p==1){
        MPC.Update_HRVHistBarData(pos1++,RR);
        if(pos1>30)
            pos1=0;
    }else if(p==2)
    {
        MPC.Update_HRVHistBarData2(pos2++,RR);
        if(pos2>30)
            pos2=0;
    }
}
void MeasurePage_P2::getProgressData2(int p,int persion)
{
    if(persion==1)
        ui->progressBar->setValue(p);
    else if(persion==2)
        ui->progressBar_2->setValue(p);
}
void MeasurePage_P2::getOver2(int p)
{
    if(p==1){
        ui->tabWidget_p1->setCurrentIndex(2);
        QString MeasureTime=uib1.MeasureTime;
        QString file=Constant::DataBasePath;
        MySql *mySql = new MySql(file);
        dbs1=mySql->DataQueryByMeasureTime(MeasureTime);
        delete mySql;
        HRVDataProcess hrvdataPro;
        HRVIndex hi=hrvdataPro.Json2HRVData(dbs1.hrvIndexResults);
        ui->progressBar_psi->setValue(hi.mp.PsiScore);//身体压力
        ui->progressBar_mental->setValue(hi.mp.MsiScore);//精神压力
        ui->progressBar_Fatigure->setValue(hi.mp.lfScore);//疲劳
        ui->progressBar_RegistPressure->setValue(hi.mp.SdnnScore);//抗压能力

    }
    if(p==2){
        ui->tabWidget_p2->setCurrentIndex(2);
        QString MeasureTime=uib2.MeasureTime;
        QString file=Constant::DataBasePath;
        MySql *mySql = new MySql(file);
        dbs2=mySql->DataQueryByMeasureTime(MeasureTime);
        delete mySql;
        HRVDataProcess hrvdataPro;
        HRVIndex hi=hrvdataPro.Json2HRVData(dbs2.hrvIndexResults);
        ui->progressBar_psi_2->setValue(hi.mp.PsiScore);//身体压力
        ui->progressBar_mental_2->setValue(hi.mp.MsiScore);//精神压力
        ui->progressBar_Fatigure_2->setValue(hi.mp.lfScore);//疲劳
        ui->progressBar_RegistPressure_2->setValue(hi.mp.SdnnScore);//抗压能力
    }

}


void MeasurePage_P2::on_bt_return_clicked()
{
    if(myHelper::ShowMessageBoxQuesion("您确认要退出吗？")==1)
        this->close();

}


void MeasurePage_P2::on_bt_print_clicked()
{
    if(Constant::ReportType==2)
    {
        PrintReport pr;
        pr.Report_HRV_Professional(dbs1);
        pr.Report_APPG_Professional(dbs1);
    }else if(Constant::ReportType==1){
        MentalReport w;
        w.setV(dbs1);
        QPrinter printer;
        //        if(!Constant::PrintType){
        //            QString ParentFolder="D:\\data\\"+dbs1.UserID;
        //            QDir dir(ParentFolder);
        //            QString fileName;
        //            if(dir.exists())
        //            {
        //                fileName=ParentFolder+"\\"+dbs1.MeasureTime+".pdf";
        //            }else
        //            {
        //                bool ok = dir.mkpath(ParentFolder);//创建多级目录
        //                if(ok)
        //                {
        //                    fileName=ParentFolder+"\\"+dbs1.MeasureTime+".pdf";
        //                }
        //            }
        //            printer.setOutputFileName(fileName);
        //        }
        printer.setResolution(300);//值越大分辨率越高
        printer.setPageMargins(QMarginsF(0, 0, 0, 0));

        QPixmap pixmap=w.grab(w.rect()); //抓取界面widget区域，可以抓取任意控件区域
        QPainter painter;
        painter.begin(&printer);
        painter.drawPixmap(0,0,pixmap); //按照坐标画图
        printer.setPageSize(QPageSize::A4);
    }else if(Constant::ReportType==3)
    {


        //输出文件到d盘data文件夹
        QPrinter printer,printer2;
        printer.setPageSize(QPageSize::A4);
        printer2.setPageSize(QPageSize::A4);
        //输出文件到d盘data文件夹
        if(printType=="输出pdf"){
            QString ParentFolder="D:\\data\\"+dbs1.UserID;
            QDir dir(ParentFolder);
            QString fileName;
            if(dir.exists())
            {
                fileName=ParentFolder+"\\"+dbs1.MeasureTime.replace(":","")+".pdf";
            }else
            {
                bool ok = dir.mkpath(ParentFolder);//创建多级目录
                if(ok)
                {
                    fileName=ParentFolder+"\\"+dbs1.MeasureTime.replace(":","")+".pdf";
                }
            }
            printer.setOutputFileName(fileName);

            printer.setResolution(300);//值越大分辨率越高
            printer.setPageMargins(QMarginsF(0, 0, 0, 0));
            Login report1;
            HRV report2;
            Anf report3;
            APPGReport report4;
            report1.setValue(dbs1);
            report2.setValue(dbs1);
            report3.setValue(dbs1);
            report4.setValue(dbs1);

            QPixmap pixmap1=report1.grab(report1.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap2=report2.grab(report2.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap3=report3.grab(report3.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap4=report4.grab(report4.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPainter painter;
            painter.begin(&printer);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();
            myHelper::ShowMessageBoxInfo("导出完毕！");

        }else if(printType=="打印机打印")
                {
            printer.setResolution(300);//值越大分辨率越高
            printer.setPageMargins(QMarginsF(0, 0, 0, 0));
            Login report1;
            HRV report2;
            Anf report3;
            APPGReport report4;
            report1.setValue(dbs1);
            report2.setValue(dbs1);
            report3.setValue(dbs1);
            report4.setValue(dbs1);

            QPixmap pixmap1=report1.grab(report1.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap2=report2.grab(report2.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap3=report3.grab(report3.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap4=report4.grab(report4.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPainter painter;
            painter.begin(&printer);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();
        }else if(printType=="输出pdf并打印")
                {
            QString ParentFolder="D:\\data\\"+dbs1.UserID;
            QDir dir(ParentFolder);
            QString fileName;
            if(dir.exists())
            {
                fileName=ParentFolder+"\\"+dbs1.MeasureTime.replace(":","")+".pdf";
            }else
            {
                bool ok = dir.mkpath(ParentFolder);//创建多级目录
                if(ok)
                {
                    fileName=ParentFolder+"\\"+dbs1.MeasureTime.replace(":","")+".pdf";
                }
            }
            printer.setOutputFileName(fileName);

            printer.setResolution(300);//值越大分辨率越高
            printer.setPageMargins(QMarginsF(0, 0, 0, 0));

            printer2.setResolution(300);//值越大分辨率越高
            printer2.setPageMargins(QMarginsF(0, 0, 0, 0));
            Login report1;
            HRV report2;
            Anf report3;
            APPGReport report4;
            report1.setValue(dbs1);
            report2.setValue(dbs1);
            report3.setValue(dbs1);
            report4.setValue(dbs1);

            QPixmap pixmap1=report1.grab(report1.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap2=report2.grab(report2.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap3=report3.grab(report3.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap4=report4.grab(report4.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPainter painter;
            painter.begin(&printer);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();

            painter.begin(&printer2);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer2.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer2.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer2.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();
            myHelper::ShowMessageBoxInfo("导出完毕！");

        }
    }
    ui->tabWidget_p1->setCurrentIndex(0);
    initControl(1);
}


void MeasurePage_P2::on_bt_gotoFirst_2_clicked()
{
    ui->tabWidget_p2->setCurrentIndex(0);
    initControl(2);
}


void MeasurePage_P2::on_bt_gotoFirst_clicked()
{
    ui->tabWidget_p1->setCurrentIndex(0);
    initControl(1);
}


void MeasurePage_P2::on_bt_print_2_clicked()
{
    if(Constant::ReportType==2)
    {
        PrintReport pr;
        pr.Report_HRV_Professional(dbs2);
        pr.Report_APPG_Professional(dbs2);
    }else if(Constant::ReportType==1){
        MentalReport w;
        w.setV(dbs2);
        QPrinter printer;
        //        if(!Constant::PrintType){
        //            QString ParentFolder="D:\\data\\"+dbs2.UserID;
        //            QDir dir(ParentFolder);
        //            QString fileName;
        //            if(dir.exists())
        //            {
        //                fileName=ParentFolder+"\\"+dbs2.MeasureTime.replace(":","")+".pdf";
        //            }else
        //            {
        //                bool ok = dir.mkpath(ParentFolder);//创建多级目录
        //                if(ok)
        //                {
        //                    fileName=ParentFolder+"\\"+dbs2.MeasureTime.replace(":","")+".pdf";
        //                }
        //            }
        //            printer.setOutputFileName(fileName);
        //        }
        printer.setResolution(300);//值越大分辨率越高
        printer.setPageMargins(QMarginsF(0, 0, 0, 0));

        QPixmap pixmap=w.grab(w.rect()); //抓取界面widget区域，可以抓取任意控件区域
        QPainter painter;
        painter.begin(&printer);
        painter.drawPixmap(0,0,pixmap); //按照坐标画图
        printer.setPageSize(QPageSize::A4);
    }else if(Constant::ReportType==3)
    {
        QPrinter printer,printer2;
        printer.setPageSize(QPageSize::A4);
        printer2.setPageSize(QPageSize::A4);
        //输出文件到d盘data文件夹
        if(printType=="输出pdf"){
            QString ParentFolder="D:\\data\\"+dbs2.UserID;
            QDir dir(ParentFolder);
            QString fileName;
            if(dir.exists())
            {
                fileName=ParentFolder+"\\"+dbs2.MeasureTime.replace(":","")+".pdf";
            }else
            {
                bool ok = dir.mkpath(ParentFolder);//创建多级目录
                if(ok)
                {
                    fileName=ParentFolder+"\\"+dbs2.MeasureTime.replace(":","")+".pdf";
                }
            }
            printer.setOutputFileName(fileName);

            printer.setResolution(300);//值越大分辨率越高
            printer.setPageMargins(QMarginsF(0, 0, 0, 0));
            Login report1;
            HRV report2;
            Anf report3;
            APPGReport report4;
            report1.setValue(dbs2);
            report2.setValue(dbs2);
            report3.setValue(dbs2);
            report4.setValue(dbs2);

            QPixmap pixmap1=report1.grab(report1.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap2=report2.grab(report2.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap3=report3.grab(report3.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap4=report4.grab(report4.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPainter painter;
            painter.begin(&printer);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();
            myHelper::ShowMessageBoxInfo("导出完毕！");

        }else if(printType=="打印机打印")
                {
            printer.setResolution(300);//值越大分辨率越高
            printer.setPageMargins(QMarginsF(0, 0, 0, 0));
            Login report1;
            HRV report2;
            Anf report3;
            APPGReport report4;
            report1.setValue(dbs2);
            report2.setValue(dbs2);
            report3.setValue(dbs2);
            report4.setValue(dbs2);

            QPixmap pixmap1=report1.grab(report1.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap2=report2.grab(report2.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap3=report3.grab(report3.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap4=report4.grab(report4.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPainter painter;
            painter.begin(&printer);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();
        }else if(printType=="输出pdf并打印")
                {
            QString ParentFolder="D:\\data\\"+dbs2.UserID;
            QDir dir(ParentFolder);
            QString fileName;
            if(dir.exists())
            {
                fileName=ParentFolder+"\\"+dbs2.MeasureTime.replace(":","")+".pdf";
            }else
            {
                bool ok = dir.mkpath(ParentFolder);//创建多级目录
                if(ok)
                {
                    fileName=ParentFolder+"\\"+dbs2.MeasureTime.replace(":","")+".pdf";
                }
            }
            printer.setOutputFileName(fileName);

            printer.setResolution(300);//值越大分辨率越高
            printer.setPageMargins(QMarginsF(0, 0, 0, 0));

            printer2.setResolution(300);//值越大分辨率越高
            printer2.setPageMargins(QMarginsF(0, 0, 0, 0));
            Login report1;
            HRV report2;
            Anf report3;
            APPGReport report4;
            report1.setValue(dbs2);
            report2.setValue(dbs2);
            report3.setValue(dbs2);
            report4.setValue(dbs2);

            QPixmap pixmap1=report1.grab(report1.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap2=report2.grab(report2.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap3=report3.grab(report3.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPixmap pixmap4=report4.grab(report4.rect()); //抓取界面widget区域，可以抓取任意控件区域
            QPainter painter;
            painter.begin(&printer);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();

            painter.begin(&printer2);
            painter.drawPixmap(0,0,pixmap1); //按照坐标画图
            printer2.newPage();
            painter.drawPixmap(0,0,pixmap2); //按照坐标画图
            printer2.newPage();
            painter.drawPixmap(0,0,pixmap3); //按照坐标画图
            printer2.newPage();
            painter.drawPixmap(0,0,pixmap4); //按照坐标画图
            painter.end();
            myHelper::ShowMessageBoxInfo("导出完毕！");

        }
    }
    ui->tabWidget_p2->setCurrentIndex(0);
    initControl(2);
}


void MeasurePage_P2::on_lineEdit_ID_editingFinished()
{
    QString file=Constant::DataBasePath;
    MySql *mySql = new MySql(file);
    QList<DataBeans>dbs=mySql->DataQueryBy(ui->lineEdit_ID->text(),"","");
    if(dbs.size()>0)
    {
        ui->lineEdit_Name->setText(dbs.at(dbs.size()-1).UserName);
        ui->lineEdit_Age->setText(dbs.at(dbs.size()-1).UserAge);
        ui->lineEdit_height->setText(dbs.at(dbs.size()-1).UserHeight);
        ui->lineEdit_weight->setText(dbs.at(dbs.size()-1).UserWeight);
    }
    delete mySql;
}


void MeasurePage_P2::on_lineEdit_ID_2_editingFinished()
{
    QString file=Constant::DataBasePath;
    MySql *mySql = new MySql(file);
    QList<DataBeans>dbs=mySql->DataQueryBy(ui->lineEdit_ID_2->text(),"","");
    if(dbs.size()>0)
    {
        ui->lineEdit_Name_2->setText(dbs.at(dbs.size()-1).UserName);
        ui->lineEdit_Age_2->setText(dbs.at(dbs.size()-1).UserAge);
        ui->lineEdit_height_2->setText(dbs.at(dbs.size()-1).UserHeight);
        ui->lineEdit_weight_2->setText(dbs.at(dbs.size()-1).UserWeight);
    }
    delete mySql;
}

